package com.peace.hospital.opdept.service.outpatientdept.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peace.hospital.entity.outpatientdept.Inpatientmessage;
import com.peace.hospital.opdept.mapper.hospitalization.SckbedMapper;
import com.peace.hospital.opdept.mapper.outpatientdept.InpatientmessageMapper;
import com.peace.hospital.opdept.service.outpatientdept.IInpatientmessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 住院病人信息表 服务实现类
 * </p>
 *
 * @author 谢晓峰
 * @since 2019-11-11
 */
@Service
public class InpatientmessageServiceImpl extends ServiceImpl<InpatientmessageMapper, Inpatientmessage> implements IInpatientmessageService {

    @Autowired
    private InpatientmessageMapper inpatientmessageMapper;
//    /**病房表*/
//    @Autowired
//    private SickrooMapper sickrooMapper;
    /**
     * 病床表*/
    @Autowired
    private SckbedMapper sckbedMapper;

    /**根据病人id查询住院收费
     * @return*/
    @Override
    public List<Inpatientmessage> selectInpatientmessageByPid(Integer pid) {
        List<Inpatientmessage> inpatientmessages = inpatientmessageMapper.selectInpatientmessagesByPid(pid);
        for (Inpatientmessage inpatientmessage : inpatientmessages) {
            //查询住院日期和出院日期时间差
            Integer integer = inpatientmessageMapper.selectDateDifference(inpatientmessage);
            //查询该床位单价
            Double aDouble = sckbedMapper.selectUnitPriceBySckid(inpatientmessage.getSckid());
            inpatientmessage.setInpatientmessageprice(aDouble);
            inpatientmessage.setTimelength(integer);
        }
        return inpatientmessages;
    }

    @Override
    public Double selectInpatientpriceeByPid(Integer pid) {
        List<Inpatientmessage> inpatientmessages = inpatientmessageMapper.selectInpatientmessagesByPid(pid);
        Double count = 0.0;
        for (Inpatientmessage inpatientmessage : inpatientmessages) {
            //查询住院日期和出院日期时间差
            Integer integer = inpatientmessageMapper.selectDateDifference(inpatientmessage);
            //查询该床位单价
            Double aDouble = sckbedMapper.selectUnitPriceBySckid(inpatientmessage.getSckid());
            //计算出总价
            count+=integer*aDouble;
        }
        return count;
    }
}
